# encoding: utf-8
class Report::RegistrationRequestReportController < ApplicationController
  def show
    @title_view = 'Solicitud de Inscripción'


  end

  def show_pdf

    search_state = params[:search_registration_request_state]
    request_and_complaint_registration_requests = RequestAndComplaint::RegistrationRequest.all
    if ! search_state.blank?
      request_and_complaint_registration_requests = RequestAndComplaint::RegistrationRequest.find(:all,:conditions=>["request_and_complaint_registration_requests.state = ? ", search_state])
    end




    pdf = Prawn::Document.new

    pdf.image "#{RAILS_ROOT}/public/images/pukara_logo.png", :width => 80, :at => [0, 715]
    pdf.text_box "Sistema de información cultural pukara",
      :at => [100, 715],
      :width => 430
    #    Titulo del reporte
    pdf.text_box "Reporte de Solicitud de Inscripción" ,
      :at => [100, 690],
      :width => 430,
      :style => :bold,
      :size => 20
    #    Cuerpo
    pdf.move_down 150

    arr = Array.new
    #esto no
    #    pdf.text_box "Hola",
    #      :at => [100, 655],
    #      :width => 430,
    #      :style => :bold,
    #      :size => 20
    #Colocando headers
    arr[0] = Array.new
    arr[0][0] = "Id"
    arr[0][1] = "Nombre"
    arr[0][2] = "Mail"
    arr[0][3] = "Descripción"
    arr[0][4] = "Estado"
    arr[0][5] = "Fecha"

    j = 1

    request_and_complaint_registration_requests.each {
      |complaint|

      arr[j] = Array.new
      arr[j][0] = complaint.id.to_s
      #      arr[j][1] = complaint.obj_complaint_type.name
      arr[j][1] = complaint.name
      arr[j][2] = complaint.mail
      arr[j][3] = complaint.description
      arr[j][4] = complaint.str_state
      arr[j][5] = complaint.created_at.strftime("%d/%m/%Y").to_s
      j = j + 1
    }

    pdf.table arr, :column_widths => [20, 80, 100, 80, 100, 70, 90], :row_colors => ["F0F0F0", "FFFFFF"], :header => true do
      row(0).border_width = 2
      row(0).font_style = :bold
    end


    
    #Pie de pagina
    pdf.repeat(:all, :dynamic => true) do
      pdf.draw_text Time.now.strftime("%d-%m-%Y").to_s, :at => [0, 0]
      pdf.draw_text pdf.page_number, :at => [530, 0]
    end
    #Nombre de reporte
    send_data pdf.render, :filename => "Reporte de Solicitud de Inscripción" << ".pdf", :type => "application/pdf"
  end


end
